#include <d3dx9.h>
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib,"d3d9.lib")
LRESULT CALLBACK MainWindowProc(HWND, UINT, WPARAM, LPARAM);
BOOL RegClass(LPCTSTR lpClassName, LPCTSTR lpMenuName, HINSTANCE hInst, WNDPROC lpfnWndProc)
{
	WNDCLASS a;
	a.style = CS_HREDRAW | CS_VREDRAW;
	a.hInstance = hInst;
	a.lpfnWndProc = lpfnWndProc;
	a.cbClsExtra = 0;
	a.cbWndExtra = 0;
	a.lpszClassName = lpClassName;
	a.lpszMenuName = lpMenuName;
	a.hIcon = LoadIcon(0, IDI_APPLICATION);
	a.hCursor = LoadCursor(0, IDC_ARROW);
	a.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	return RegisterClass(&a);
}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	
	case WM_CLOSE:
		DestroyWindow(hWnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;

	}
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(
	HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR nCmdLine,
	int nCmdShow
)
{
	static MSG msg;
	RegClass("MainClass", nullptr, hInstance, MainWindowProc);
	HWND hWnd = CreateWindow("MainClass", "MainWindow", WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, nullptr, nullptr, hInstance, nullptr);
	ShowWindow(hWnd, SW_SHOW);
	UpdateWindow(hWnd);
	
	while (1)
	{
		PeekMessage(&msg, nullptr, NULL, NULL, PM_REMOVE);
		if (msg.message == WM_QUIT)break;
		TranslateMessage(&msg);
		DispatchMessage(&msg);

	}
	return msg.wParam;
}
